# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-rack-session
pkgver=2.0.0
pkgrel=1
pkgdesc='Session management implementation for Rack.'
url="https://github.com/rack/rack-session"
arch=('any')
license=('MIT')
depends=('ruby' 'ruby-rack')
makedepends=('ruby-rdoc')
checkdepends=('ruby-rake' 'ruby-minitest' 'ruby-minitest-global_expectations' 'ruby-minitest-sprint')
options=('!emptydirs')
source=("${pkgname}-v${pkgver}.tar.gz::$url/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('3bc3dc599ca781b182afbc1208486e6f268d26d7d1026c73c170a9990b86f5ad')
sha512sums=('8975a85845fa4dbdf22c10793fb2bb1a69aed3242c70c45b1d436448243e65ad77ecbfb17c8f2ef6f780b81ef480f8a46c5623e36dacc95401cd59a1510748f8')

prepare() {
  cd rack-session-${pkgver}
  sed -r 's|~>|>=|g' -i rack-session.gemspec
}

build() {
  cd rack-session-${pkgver}

  local _gemdir="$(gem env gemdir)"

  gem build rack-session.gemspec

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/${_gemdir}" \
    --bindir "tmp_install/usr/bin" \
    "rack-session-${pkgver}.gem"

  rm -rf "tmp_install/${_gemdir}/cache/"
}

check() {
  cd rack-session-${pkgver}

  local _gemdir="$(gem env gemdir)"

  GEM_HOME="tmp_install/${_gemdir}" rake test
}

package() {
  cd rack-session-${pkgver}

  cp -a tmp_install/* "${pkgdir}"

  install -Dm 0644 license.md --target-directory "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 0644 {readme,security}.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}
